package hkr.budget;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.util.Log;

public class BudgetDataSource {
	
	private SQLiteDatabase database;
	private DatabaseBuilder queryDB;
	
	public BudgetDataSource(Context context){
		
		queryDB = new DatabaseBuilder(context);
		
	}

	public void open() throws SQLiteException{
		
		database = queryDB.getWritableDatabase();
	}
	
	public void close(){
		queryDB.close();
	}
	
	public void saveExpense(String date, String expense, String category, String paymentType, double paymentAmount){
		database.execSQL("INSERT INTO " + DatabaseBuilder.TABLE_BUDGET + "("
				+ DatabaseBuilder.DATE +", " + DatabaseBuilder.EXPENSE + ", " + DatabaseBuilder.CATEGORY + ", " 
				+ DatabaseBuilder.PAYMENT_TYPE + ", " + DatabaseBuilder.PAYMENT_AMOUNT + ") " + "VALUES ('" + date + "', '" + expense 
				+ "', '" + category + "', '" + paymentType + "', " + paymentAmount + ");" );		
		
		Log.i("Budget Data Source", "Database INSERT statement complete.");
		
	}
	
	public Cursor getData(){
		
		return database.query(false, DatabaseBuilder.TABLE_BUDGET, null, null, null, null, null, null, null);
	}
}
